using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_ABPOSFS
    {
        public DataRow Convert2ICC_ABPOSFS(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryICC_ABPOSFS(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["KRS"] = " ".PadRight(2 ); 
         dwReturn["LFD"] = " ".PadRight(6 ); 
         dwReturn["SEASON"] = " ".PadRight(5 ); 
         dwReturn["SECTION"] = " ".PadRight(10 ); 
         dwReturn["ART"] = " ".PadRight(20 ); 
         dwReturn["VAR"] = " ".PadRight(3 ); 
         dwReturn["FARBE"] = " ".PadRight(10 ); 
         dwReturn["PHOTO"] = " ".PadRight(200 ); 
         dwReturn["CDES"] = " ".PadRight(60 ); 
         dwReturn["ARTDES"] = " ".PadRight(60 ); 
         dwReturn["EXTPRODUCER"] = " ".PadRight(10 ); 
         dwReturn["STARTDAT"] = " ".PadRight(0 ); 
         dwReturn["DELDAT"] = " ".PadRight(0 ); 
         dwReturn["ETDDAT"] = " ".PadRight(0 ); 
         dwReturn["AETDDAT"] = " ".PadRight(0 ); 
         dwReturn["CAPP"] = " ".PadRight(3 ); 
         dwReturn["SMAPP"] = " ".PadRight(3 ); 
         dwReturn["SZAPP"] = " ".PadRight(3 ); 
         dwReturn["WAPP1"] = " ".PadRight(3 ); 
         dwReturn["WAPP2"] = " ".PadRight(3 ); 
         dwReturn["WAPP3"] = " ".PadRight(3 ); 
         dwReturn["WAPP4"] = " ".PadRight(3 ); 
         dwReturn["WAPP5"] = " ".PadRight(3 ); 
         dwReturn["WAPP6"] = " ".PadRight(3 ); 
         dwReturn["WAPP7"] = " ".PadRight(3 ); 
         dwReturn["WAPP8"] = " ".PadRight(3 ); 
         dwReturn["AAPP1"] = " ".PadRight(3 ); 
         dwReturn["AAPP2"] = " ".PadRight(3 ); 
         dwReturn["AAPP3"] = " ".PadRight(3 ); 
         dwReturn["AAPP4"] = " ".PadRight(3 ); 
         dwReturn["AAPP5"] = " ".PadRight(3 ); 
         dwReturn["AAPP6"] = " ".PadRight(3 ); 
         dwReturn["AAPP7"] = " ".PadRight(3 ); 
         dwReturn["AAPP8"] = " ".PadRight(3 ); 
         dwReturn["WCHECK"] = " ".PadRight(3 ); 
         dwReturn["EXTTECH"] = " ".PadRight(20 ); 
         dwReturn["FPRICE"] = " ".PadRight(0 ); 
         dwReturn["TQTY"] = " ".PadRight(0 ); 
         dwReturn["REMARK"] = " ".PadRight(200 ); 
         dwReturn["S"] = " ".PadRight(0 ); 
         dwReturn["M"] = " ".PadRight(0 ); 
         dwReturn["L"] = " ".PadRight(0 ); 
         dwReturn["XL"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapICC_ABPOSFS(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_ABPOSFS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryICC_ABPOSFS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapICC_ABPOSFS(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertICC_ABPOSFS(dwLocal, ITXDBVERSION);
            }
            UpdateICC_ABPOSFS(dwLocal);
        }
        public void InsertICC_ABPOSFS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ICC_ABPOSFS(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryICC_ABPOSFS(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ICC_ABPOSFS WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ICC_ABPOSFS  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_ABPOSFS";
            Return = Result;
            return Return;
        }
        public void DeleteICC_ABPOSFS(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_ABPOSFS   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateICC_ABPOSFS(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ICC_ABPOSFS SET "
                    +"KRS= :KRS,"
                    +"LFD= :LFD,"
                    +"SEASON= :SEASON,"
                    +"SECTION= :SECTION,"
                    +"ART= :ART,"
                    +"VAR= :VAR,"
                    +"FARBE= :FARBE,"
                    +"PHOTO= :PHOTO,"
                    +"CDES= :CDES,"
                    +"ARTDES= :ARTDES,"
                    +"EXTPRODUCER= :EXTPRODUCER,"
                    +"STARTDAT= :STARTDAT,"
                    +"DELDAT= :DELDAT,"
                    +"ETDDAT= :ETDDAT,"
                    +"AETDDAT= :AETDDAT,"
                    +"CAPP= :CAPP,"
                    +"SMAPP= :SMAPP,"
                    +"SZAPP= :SZAPP,"
                    +"WAPP1= :WAPP1,"
                    +"WAPP2= :WAPP2,"
                    +"WAPP3= :WAPP3,"
                    +"WAPP4= :WAPP4,"
                    +"WAPP5= :WAPP5,"
                    +"WAPP6= :WAPP6,"
                    +"WAPP7= :WAPP7,"
                    +"WAPP8= :WAPP8,"
                    +"AAPP1= :AAPP1,"
                    +"AAPP2= :AAPP2,"
                    +"AAPP3= :AAPP3,"
                    +"AAPP4= :AAPP4,"
                    +"AAPP5= :AAPP5,"
                    +"AAPP6= :AAPP6,"
                    +"AAPP7= :AAPP7,"
                    +"AAPP8= :AAPP8,"
                    +"WCHECK= :WCHECK,"
                    +"EXTTECH= :EXTTECH,"
                    +"FPRICE= :FPRICE,"
                    +"TQTY= :TQTY,"
                    +"REMARK= :REMARK,"
                    +"S= :S,"
                    +"M= :M,"
                    +"L= :L,"
                    +"XL= :XL,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"].ToString(); 
          or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"].ToString(); 
          or1.Parameters.Add("SEASON", OracleType.NVarChar).Value = dwData["SEASON"].ToString(); 
          or1.Parameters.Add("SECTION", OracleType.NVarChar).Value = dwData["SECTION"].ToString(); 
          or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"].ToString(); 
          or1.Parameters.Add("VAR", OracleType.NVarChar).Value = dwData["VAR"].ToString(); 
          or1.Parameters.Add("FARBE", OracleType.NVarChar).Value = dwData["FARBE"].ToString(); 
          or1.Parameters.Add("PHOTO", OracleType.NVarChar).Value = dwData["PHOTO"].ToString(); 
          or1.Parameters.Add("CDES", OracleType.NVarChar).Value = dwData["CDES"].ToString(); 
          or1.Parameters.Add("ARTDES", OracleType.NVarChar).Value = dwData["ARTDES"].ToString(); 
          or1.Parameters.Add("EXTPRODUCER", OracleType.NVarChar).Value = dwData["EXTPRODUCER"].ToString(); 
          or1.Parameters.Add("STARTDAT", OracleType.NVarChar).Value = dwData["STARTDAT"].ToString(); 
          or1.Parameters.Add("DELDAT", OracleType.NVarChar).Value = dwData["DELDAT"].ToString(); 
          or1.Parameters.Add("ETDDAT", OracleType.NVarChar).Value = dwData["ETDDAT"].ToString(); 
          or1.Parameters.Add("AETDDAT", OracleType.NVarChar).Value = dwData["AETDDAT"].ToString(); 
          or1.Parameters.Add("CAPP", OracleType.NVarChar).Value = dwData["CAPP"].ToString(); 
          or1.Parameters.Add("SMAPP", OracleType.NVarChar).Value = dwData["SMAPP"].ToString(); 
          or1.Parameters.Add("SZAPP", OracleType.NVarChar).Value = dwData["SZAPP"].ToString(); 
          or1.Parameters.Add("WAPP1", OracleType.NVarChar).Value = dwData["WAPP1"].ToString(); 
          or1.Parameters.Add("WAPP2", OracleType.NVarChar).Value = dwData["WAPP2"].ToString(); 
          or1.Parameters.Add("WAPP3", OracleType.NVarChar).Value = dwData["WAPP3"].ToString(); 
          or1.Parameters.Add("WAPP4", OracleType.NVarChar).Value = dwData["WAPP4"].ToString(); 
          or1.Parameters.Add("WAPP5", OracleType.NVarChar).Value = dwData["WAPP5"].ToString(); 
          or1.Parameters.Add("WAPP6", OracleType.NVarChar).Value = dwData["WAPP6"].ToString(); 
          or1.Parameters.Add("WAPP7", OracleType.NVarChar).Value = dwData["WAPP7"].ToString(); 
          or1.Parameters.Add("WAPP8", OracleType.NVarChar).Value = dwData["WAPP8"].ToString(); 
          or1.Parameters.Add("AAPP1", OracleType.NVarChar).Value = dwData["AAPP1"].ToString(); 
          or1.Parameters.Add("AAPP2", OracleType.NVarChar).Value = dwData["AAPP2"].ToString(); 
          or1.Parameters.Add("AAPP3", OracleType.NVarChar).Value = dwData["AAPP3"].ToString(); 
          or1.Parameters.Add("AAPP4", OracleType.NVarChar).Value = dwData["AAPP4"].ToString(); 
          or1.Parameters.Add("AAPP5", OracleType.NVarChar).Value = dwData["AAPP5"].ToString(); 
          or1.Parameters.Add("AAPP6", OracleType.NVarChar).Value = dwData["AAPP6"].ToString(); 
          or1.Parameters.Add("AAPP7", OracleType.NVarChar).Value = dwData["AAPP7"].ToString(); 
          or1.Parameters.Add("AAPP8", OracleType.NVarChar).Value = dwData["AAPP8"].ToString(); 
          or1.Parameters.Add("WCHECK", OracleType.NVarChar).Value = dwData["WCHECK"].ToString(); 
          or1.Parameters.Add("EXTTECH", OracleType.NVarChar).Value = dwData["EXTTECH"].ToString(); 
          or1.Parameters.Add("FPRICE", OracleType.NVarChar).Value = dwData["FPRICE"].ToString(); 
          or1.Parameters.Add("TQTY", OracleType.NVarChar).Value = dwData["TQTY"].ToString(); 
          or1.Parameters.Add("REMARK", OracleType.NVarChar).Value = dwData["REMARK"].ToString(); 
          or1.Parameters.Add("S", OracleType.NVarChar).Value = dwData["S"].ToString(); 
          or1.Parameters.Add("M", OracleType.NVarChar).Value = dwData["M"].ToString(); 
          or1.Parameters.Add("L", OracleType.NVarChar).Value = dwData["L"].ToString(); 
          or1.Parameters.Add("XL", OracleType.NVarChar).Value = dwData["XL"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
